var mongoose = require('mongoose');
var config = require('../config');
//models
require('./User');
require('./tab');
require('./topic');
require('./reply');
require('./reply_opinion');

exports.User = mongoose.model('User');
exports.Tab = mongoose.model('Tab');
exports.Topic = mongoose.model('Topic');
exports.Reply = mongoose.model('Reply');
exports.ReplyOpinion = mongoose.model('ReplyOpinion');

mongoose.connect('mongodb://127.0.0.1:27017/itclub', function (err) {
	if (err) {
		console.error('fail to connect db:' + err.message);
		return;
	}
	//tabs
	exports.Tab.find({}, function (err, tabs) {
		if (err) {
			console.log(err.message);
			return;
		}
		tabs.forEach(function (tab) {
			config.tabs.push(tab);
			config.tabs[tab._id] = tab;
		});
	})
});